Skip to content

feat: add Twilio Lookup v2 API tests#1285

Merged
fbm3307 merged 12 commits into
codeready-toolchain:masterfrom
fbm3307:twiliolapi
Jun 15, 2026
Merged

feat: add Twilio Lookup v2 API tests#1285
fbm3307 merged 12 commits into
codeready-toolchain:masterfrom
fbm3307:twiliolapi

Conversation

@fbm3307

@fbm3307 fbm3307 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Add twilio v2 lookup api and test related to it .

related Prs:
Registration-Service: codeready-toolchain/registration-service#595
toolchain-Common: codeready-toolchain/toolchain-common#532
host operator: codeready-toolchain/host-operator#1268
API: codeready-toolchain/api#509

Summary by CodeRabbit

  • New Features

    • Added a configurable phone lookup mode (disabled, enabled, log) affecting signup verification: disabled skips lookups, log records lookup results, enabled can block rejected numbers while skipping lookups for US numbers.
  • Tests

    • Added end-to-end tests covering phone lookup modes and signup verification outcomes.
    • Added test utilities to wait for signup annotations and validate phone-lookup configuration.

Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@openshift-ci openshift-ci Bot requested review from jrosental and mfrancisc June 4, 2026 09:27
@openshift-ci openshift-ci Bot added the approved label Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Bumps dependency pins and replace directives, adds wait-criterion helpers, sets ToolchainConfig phoneLookupMode to 'disabled' in test manifest, and introduces an e2e TestPhoneLookupMode with subtests for disabled, log, and enabled behaviors.

Changes

Phone Lookup Mode E2E

Layer / File(s) Summary
Dependency updates and wait helpers
go.mod, testsupport/wait/host.go
Bumps github.com/codeready-toolchain/api require and adds replace directives; adds UntilUserSignupHasAnnotation, UntilUserSignupHasAnnotationNotEmpty, and UntilToolchainConfigHasPhoneLookupMode.
Test ToolchainConfig baseline
deploy/host-operator/e2e-tests/toolchainconfig.yaml
Inserts phoneLookupMode: 'disabled' under spec.host.deactivation.verification for the e2e baseline.
Phone lookup mode e2e test suite
test/e2e/parallel/phone_lookup_test.go
Adds TestPhoneLookupMode with subtests for disabled, log, and enabled modes (including US/UK cases) and Twilio magic-number constants; validates HTTP responses and UserSignup annotations.

Sequence Diagram

sequenceDiagram
  participant Test as E2E Test
  participant Config as ToolchainConfig
  participant Signup as UserSignup
  participant Endpoint as /api/v1/signup/verification
  Test->>Config: Set or verify phoneLookupMode (disabled/log/enabled)
  Test->>Signup: Create UserSignup with phone number
  Test->>Endpoint: PUT /api/v1/signup/verification
  Endpoint->>Signup: Evaluate phone lookup and update annotations
  Endpoint->>Test: Return HTTP status and verification code (if any)
  Test->>Signup: Assert annotations and response match expected mode behavior
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels: feature, test, dependencies

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Twilio Lookup v2 API tests' accurately reflects the main changes in the PR, which include e2e tests for phone lookup functionality using Twilio's API.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Linked repositories: Couldn't analyze codeready-toolchain/api - clone failed: Clone operation failed: Stream initialization permanently failed: 14 UNAVAILABLE: upstream connect error or disconnect/reset before headers. reset reason: connection timeout


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added dependencies Pull requests that update a dependency file feature New feature or request test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness) labels Jun 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/e2e/parallel/phone_lookup_test.go (1)

128-132: 💤 Low value

Consider simplifying the phone number generation logic.

The current implementation works correctly but the slice operation suffix[len(suffix)-5:] could be more direct. Consider taking the first 5 digits after generating the UUID string:

 func uniqueUKPhoneNumber() string {
-	// UK mobile numbers are 10 digits after country code; use a unique suffix to avoid phone-in-use conflicts
-	suffix := strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "")[:10]
-	return "77009" + suffix[len(suffix)-5:]
+	// UK mobile numbers are 10 digits after country code; use a unique 5-digit suffix to avoid phone-in-use conflicts
+	suffix := strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "")[:5]
+	return "77009" + suffix
 }

This eliminates the need to slice from the end and makes the intent clearer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/e2e/parallel/phone_lookup_test.go` around lines 128 - 132, The
uniqueUKPhoneNumber function uses a UUID-derived suffix and then takes the last
5 chars via suffix[len(suffix)-5:], which is unnecessarily indirect; change it
to take the first 5 characters of the generated suffix (e.g., suffix[:5]) and
return "77009" + that substring so the intent is clearer and simpler while
preserving the unique phone number format.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@go.mod`:
- Around line 145-147: Remove the temporary forked-module replace directives
from go.mod before merging: delete the two replace lines that map
github.com/codeready-toolchain/api => github.com/fbm3307/toolchainapi@... and
github.com/codeready-toolchain/toolchain-common =>
github.com/fbm3307/toolchain-common@.... If those forks are required while
upstream PRs are pending, add a clear TODO comment above each replace with the
upstream PR URLs and a plan to remove them, but ensure the final merge removes
the replace mappings so builds use the canonical github.com/codeready-toolchain
modules.

---

Nitpick comments:
In `@test/e2e/parallel/phone_lookup_test.go`:
- Around line 128-132: The uniqueUKPhoneNumber function uses a UUID-derived
suffix and then takes the last 5 chars via suffix[len(suffix)-5:], which is
unnecessarily indirect; change it to take the first 5 characters of the
generated suffix (e.g., suffix[:5]) and return "77009" + that substring so the
intent is clearer and simpler while preserving the unique phone number format.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: df94b267-4f98-4cff-a556-b6e27331a59d

📥 Commits

Reviewing files that changed from the base of the PR and between 13a810f and d360c7a.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • deploy/host-operator/e2e-tests/toolchainconfig.yaml
  • go.mod
  • test/e2e/parallel/phone_lookup_test.go
  • testsupport/wait/host.go
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: GolangCI Lint
  • GitHub Check: govulncheck
  • GitHub Check: Unit Tests
  • GitHub Check: Build & push operator bundles & dashboard image for e2e tests
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

-Focus on major issues impacting performance, readability, maintainability and security. Avoid nitpicks and avoid verbosity.

Files:

  • deploy/host-operator/e2e-tests/toolchainconfig.yaml
  • go.mod
  • testsupport/wait/host.go
  • test/e2e/parallel/phone_lookup_test.go
🧠 Learnings (1)
📚 Learning: 2025-08-01T09:54:02.406Z
Learnt from: fbm3307
Repo: codeready-toolchain/toolchain-e2e PR: 1175
File: deploy/base1ns-gotemplate/cluster.yaml:69-70
Timestamp: 2025-08-01T09:54:02.406Z
Learning: The codeready-toolchain/toolchain-e2e project is not using the latest version of Kubernetes yet, so deprecated API groups like `ingresses.extensions` may still be functional in their current environment. Consider this when reviewing resource quotas and API usage.

Applied to files:

  • go.mod
🔇 Additional comments (4)
testsupport/wait/host.go (2)

488-514: LGTM!


1729-1740: LGTM!

deploy/host-operator/e2e-tests/toolchainconfig.yaml (1)

23-23: LGTM!

test/e2e/parallel/phone_lookup_test.go (1)

18-126: LGTM!

Comment thread go.mod Outdated
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai coderabbitai Bot removed dependencies Pull requests that update a dependency file feature New feature or request test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness) labels Jun 4, 2026
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai coderabbitai Bot added dependencies Pull requests that update a dependency file feature New feature or request test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness) labels Jun 4, 2026
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai coderabbitai Bot removed dependencies Pull requests that update a dependency file feature New feature or request test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness) labels Jun 4, 2026
Comment thread test/e2e/parallel/phone_lookup_test.go
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai coderabbitai Bot added dependencies Pull requests that update a dependency file feature New feature or request labels Jun 5, 2026
@coderabbitai coderabbitai Bot added the test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness) label Jun 5, 2026
fbm3307 and others added 3 commits June 8, 2026 16:00
- Resolve go.mod/go.sum conflicts from upstream merge
- Update replace directives to latest toolchainapi and toolchain-common
- Update phone_lookup_test.go to use consolidated phone-lookup-details
  JSON annotation instead of removed individual annotation constants
- Use PhoneLookupExcludedCountries config in US number skip test

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Feny Mehta <fbm3307@gmail.com>
…ommon master

Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread test/e2e/parallel/phone_lookup_test.go Outdated
Comment on lines +49 to +53
t.Run("phoneLookupMode can be set on ToolchainConfig", func(t *testing.T) {
// Non-default value: CRD default "log" is omitted in spec when set explicitly, so use "enabled" to verify persistence.
hostAwait.UpdateToolchainConfig(t, testconfig.RegistrationService().Verification().PhoneLookupMode(toolchainv1alpha1.PhoneLookupModeEnabled))
VerifyToolchainConfig(t, hostAwait, wait.UntilToolchainConfigHasPhoneLookupMode(toolchainv1alpha1.PhoneLookupModeEnabled))
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to have a test for this? Let's keep the e2e tests focused on the functionality

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread test/e2e/parallel/phone_lookup_test.go
Comment thread test/e2e/parallel/phone_lookup_test.go Outdated
Comment thread test/e2e/parallel/phone_lookup_test.go Outdated
Comment on lines +70 to +86
t.Run("log mode stores phone lookup annotations when lookup succeeds", func(t *testing.T) {
hostAwait.UpdateToolchainConfig(t, testconfig.RegistrationService().Verification().PhoneLookupMode(toolchainv1alpha1.PhoneLookupModeLog))

userSignup, token := signup(t, hostAwait)
NewHTTPRequest(t).
InvokeEndpoint("PUT", route+"/api/v1/signup/verification", token,
fmt.Sprintf(`{ "country_code":"+44", "phone_number":"%s" }`, twilioMagicPhoneHighRiskBlocked), http.StatusNoContent)

userSignup, err := hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasAnnotationNotEmpty(toolchainv1alpha1.UserSignupVerificationCodeAnnotationKey))
require.NoError(t, err)

assert.Equal(t, "rejected", phoneLookupDetailsResult(t, userSignup))
assert.Equal(t, "high", userSignup.Annotations[toolchainv1alpha1.UserSignupPhoneLookupCarrierRiskAnnotationKey])
assert.Equal(t, "true", userSignup.Annotations[toolchainv1alpha1.UserSignupPhoneLookupNumberBlockedAnnotationKey])
assert.NotEmpty(t, userSignup.Annotations[toolchainv1alpha1.UserSignupVerificationCodeAnnotationKey])
})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important thing here is also that the UserSignup is not rejected and thus also provisioned - I'm missing the verification here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added assert.False(t, states.Rejected(userSignup), "UserSignup should NOT be rejected in log mode") to verify the signup is not rejected and can proceed to provisioning.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not using VerifyResourcesProvisionedForSignup?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was no particular reason, we are checking that now

Comment thread test/e2e/parallel/phone_lookup_test.go
fbm3307 and others added 2 commits June 9, 2026 15:44
- Remove config persistence and disabled mode tests (duplicative)
- Use states.SetRejected/Rejected instead of JSON annotation
- Add // given // when // then comments to all subtests
- Verify UserSignup is NOT rejected in log mode
- Fix US number test: use magic number instead of UUID hex digits
- Remove unused phoneLookupDetailsResult helper

Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The previous UUID-derived number had hex chars, then the magic number
+11234567890 had invalid area code 123. Use +12025550123 which is in
the NANPA 555-0100..0199 range reserved for fictional use, safe with
Twilio test credentials.

Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@fbm3307 fbm3307 requested review from MatousJobanek and metlos June 10, 2026 06:21
Comment thread test/e2e/parallel/phone_lookup_test.go
Comment thread test/e2e/parallel/phone_lookup_test.go
Comment thread test/e2e/parallel/phone_lookup_test.go
…ning

- Add t.Parallel() for parallel test execution
- Add "enabled mode rejects high-risk phone number" test case
- Complete verification flow and call VerifyResourcesProvisionedForSignup
  in log mode and US-skip tests to confirm full provisioning
- Verify states.Rejected assertions in all applicable tests

Signed-off-by: Feny Mehta <fbm3307@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@sonarqubecloud

Copy link
Copy Markdown

@fbm3307 fbm3307 requested a review from MatousJobanek June 11, 2026 09:23
Comment thread test/e2e/parallel/phone_lookup_test.go
Comment thread test/e2e/parallel/phone_lookup_test.go
@openshift-ci

openshift-ci Bot commented Jun 11, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fbm3307, MatousJobanek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [MatousJobanek,fbm3307]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fbm3307 fbm3307 merged commit 50f6e35 into codeready-toolchain:master Jun 15, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved dependencies Pull requests that update a dependency file feature New feature or request test Work that adds, fixes, or maintains automated tests or coverage (unit, integration, e2e, flakiness)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants